import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.InetAddress;
import java.net.Socket;

public class FilePutClient {
    public static void main(String[] args) {
        try {
            // 创建客户端对象
            Socket client = new Socket(InetAddress.getLocalHost(),3000);
            // 客户端向服务器端写入
            OutputStream out = client.getOutputStream();
            // 从硬盘里读入内存变成字节数组，输入流
            FileInputStream fis = new FileInputStream("G:\\data\\2000.jpg");
            // 图片的读取
            byte[] buf = new byte[1024];
            int len = 0;
            while ((len=fis.read(buf))!=-1){
                out.write(buf,0,len);
            }
            // 必须关闭，不关闭服务器读不到-1
            client.shutdownOutput();
            // 客户端接收服务器端响应信息
            InputStream is = client.getInputStream();
            byte[] buf1 = new byte[1024];
            int len1 = 0;
            while ((len1=is.read(buf1))!=-1){
                System.out.println(new String(buf1,0,len1));
                len1 = is.read(buf1);
            }
            // 关闭流 连接
            out.close();
            is.close();
            fis.close();
            client.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
